package org.tc.client.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.tc.client.entity.Users;
import org.tc.client.mapper.UsersMapper;
import org.tc.client.service.UserServices;

import java.util.List;
import java.util.Random;


@RestController
public class UserServiceImpl implements UserServices {

    @Autowired
    private UsersMapper usersMapper;


    @Override
    public Users login(String phone, String pwd) {
        return usersMapper.login(phone, pwd);
    }

    @Override
    public int insertUser(@RequestBody Users users) {
        System.out.println("1");
        return usersMapper.insertUser(users);
    }

    @Override
    public Users selectUser(@RequestParam("id") Integer id) {
        return usersMapper.selectUser(id);
    }

    @Override
    public Users selectByPhone(@RequestParam("phone") String phone,@RequestParam(name = "nickname",required = false) String nickname) {
        return usersMapper.selectByPhone(phone,nickname);
    }

    @Override
    public int updateUsersById(@RequestBody Users users) {
        return usersMapper.updateUserById(users);
    }

    @Override
    public int insertBuMemNum(@RequestBody Users users) {
        Random rand = new Random();
        int name1=0;
        int name2=0;
        int name=0;
        name1=rand.nextInt(10000) + 1;
        name2=rand.nextInt(10000) + 1;
        name= name1+name2;
        int member=name1*name2;
        users.setNickname("Hi"+name);
        users.setPwd("123456");
        users.setMembernumber(String.valueOf(member));
        users.setMember(10);
        return usersMapper.insertBuMemNum(users);

    }

    @Override
    public int updateScoreByMemNumber(@RequestBody Users user) {
        return usersMapper.updateScoreByMemNumber(user);
    }

}
